<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <script type="text/javascript">
var data = {
  "rateList": [{
    "trendPriceCommunity": "22500,22571,22643,24300,29500,29257,29263,29100,28419,29052,28200,28589;2016-12,2017-01,2017-02,2017-03,2017-04,2017-05,2017-06,2017-07,2017-08,2017-09,2017-10,2017-11",
    "districtName": "李沧区",
    "cityName": "青岛市",
    "trendNetlist": "7,7,3,4,3;2017-06,2017-08,2017-09,2017-10,2017-11"
  }],
  "communityName": "绿城御园C区",
  "districtList": [{
    "trendPriceCity": "12325,12712,13098,13788,14751,15080,15770,16271,16540,17732,18168,18213;2016-12,2017-01,2017-02,2017-03,2017-04,2017-05,2017-06,2017-07,2017-08,2017-09,2017-10,2017-11"
  }],
  "cityList": [{
    "trendPriceCity": "11649,11856,12077,12471,13196,13552,13917,14234,14440,15327,16066,16261;2016-12,2017-01,2017-02,2017-03,2017-04,2017-05,2017-06,2017-07,2017-08,2017-09,2017-10,2017-11"
  }]
}
data.rateList = data.rateList[0]
data.districtList = data.districtList[0]
data.cityList = data.cityList[0]

data.rateList.trendPriceCommunity = formatData(data.rateList.trendPriceCommunity)
data.rateList.trendNetlist = formatData(data.rateList.trendNetlist)
data.districtList.trendPriceCity = formatData(data.districtList.trendPriceCity)
data.cityList.trendPriceCity = formatData(data.cityList.trendPriceCity)

function formatData(str){
  var arr = str.split(';')
  arr[0] = arr[0].split(',');
  arr[1] = arr[1].split(',');
  var result = {};
  for(var i=0;i<arr[0].length;i++){
    result[arr[1][i]] = {
      date: arr[1][i],
      value: arr[0][i]
    }
  }
  return result
}

function fillZero(arr){
  for(var o in arr[0]){
    for(var i=1;i<arr.length;i++){
      if(!arr[i][o]){
        arr[i][o] = {
          date: arr[0][o].date,
          value: '0'
        }
      }
    }
  }
}

function mapToArray(obj){
  var result = [];
  for(var o in obj){
    result.push(obj[o])
  }
  return result.sort(function(a,b){
    return a.date>b.date?1:-1
  });
}

var arr = [data.rateList.trendPriceCommunity,data.rateList.trendNetlist,data.districtList.trendPriceCity,data.cityList.trendPriceCity]
for(var i=0;i<4;i++){
  fillZero(arr);
  arr.push(arr.shift());
}

data.rateList.trendPriceCommunity = mapToArray(data.rateList.trendPriceCommunity)
data.rateList.trendNetlist = mapToArray(data.rateList.trendNetlist)
data.districtList.trendPriceCity = mapToArray(data.districtList.trendPriceCity)
data.cityList.trendPriceCity = mapToArray(data.cityList.trendPriceCity)
console.log(data)
//communityName == rateList>trendPriceCommunity   这个是小区名字，对应的数据是rateList下的trendPriceCommunity
//trendNetlist是挂牌量
//districtName =>districtList>trendPriceCity  这个是行政区名字，对应的数据是districtList下的trendPriceCity  
//cityName => cityList>trendPriceCity  这个是城市名字，对应的数据是cityList下的trendPriceCity  

  </script>
</body>
</html>